﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using Aoxuelf.MDSTool.Utils;

namespace Aoxuelf.MDSTool.Model
{
    public class RecentLocation : INotifyPropertyChanged
    {
        private string mDisplayName;

        public RecentLocation(string path, string displayName)
        {
            SafeGuard.NotArgNull(path, "path");
            SafeGuard.NotArgNull(displayName, "displayName");

            this.Location = path;
            this.mDisplayName = displayName;
            this.LastUpdatedDate = DateTime.Now;
        }

        public RecentLocation(string path)
            : this(path, path)
        {
        }

        public string Location { get; private set; }

        public DateTime LastUpdatedDate { get; set; }

        public string DisplayName 
        {
            get { return this.mDisplayName; }
            set 
            { 
                SafeGuard.NotArgNull(value, "DisplayName"); 
                this.mDisplayName = value;
                OnPropertyChanged("DisplayName");
            }
        }

        public bool IsFile
        {
            get { return Path.HasExtension(this.Location); }
        }

        public void Open()
        {
            if (this.IsFile)
            {
                ExplorerHelper.OpenFile(this.Location);
            }
            else
            {
                ExplorerHelper.OpenFolder(this.Location);
            }
        }

        public override string ToString()
        {
            return this.DisplayName;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
